package com.bascker.algorithm.base.linkedlist;

import com.bascker.algorithm.base.Node;
import lombok.Getter;
import lombok.Setter;

import java.util.Iterator;
import java.util.Objects;

@Getter
@Setter
public class DoublyListNode<T> extends Node<T> {

    private DoublyListNode<T> pre;
    private DoublyListNode<T> next;

    @Override
    public Iterator<T> iterator() {
        return new DlnIterator();
    }

    class DlnIterator implements Iterator<T> {

        private DoublyListNode<T> cur = DoublyListNode.this;

        @Override
        public boolean hasNext() {
            return Objects.isNull(cur.getNext());
        }

        @Override
        public T next() {
            final T item = cur.item;
            cur = cur.getNext();
            return item;
        }
    }

}
